const {
    login,
    register
} = require('../../service/login/login')

exports.loginApi = async ctx => {
    try {
        // 获取url 字段 继而判断接下来操作
        let url = ctx.request.url.split("/");
        let urlKey = url[2].split("?")[0]
        const { username, password, nickname } = ctx.request.body || '';
        let res;
        switch (ctx.request.method) {
            case "POST": if (urlKey == 'login') {
                res = await login({ username, password })
            }else if(urlKey == 'register'){
                res = await register({username,password, nickname})
            }
        }
        ctx.body = res
    } catch (err) { return { msg:'操作失败', code: '400', err } }
}